<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
  </head>
  <body>
    <input type="button" value="按钮" id="btn" />
    <ul id="ul">
      <li>西施</li>
      <li>貂蝉</li>
      <li>昭君</li>
      <li>凤姐</li>
      <li>芙蓉姐姐</li>
    </ul>

    <script>
      var ul = document.querySelector('#ul')
      var btn = document.querySelector('input')
      btn.onclick = function () {
        var li = document.createElement('li')
        li.innerHTML = '陈君'
        ul.appendChild(li)
      }
      ul.onclick = function (e) {
        // e.target.remove()
        for (i = 0; i < this.children.length; i++) {
          ul.children[i].style.backgroundColor = ''
        }
        e.target.style.backgroundColor = 'pink'
      }
    </script>
  </body>
</html>
